
<template>
	<view class="">
	
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @up="upCallback" :up="upOption"  @down="downCallback">
			<view v-if="tip" class="flex-content m-t-36">
				
			
			<view class="flex col-center row-between br10 p-l-24 p-r-24 bg-white" style="height: 50rpx; width: 710rpx;">
				<view style="color:#686868;" class="xs">历史记录（点击近期记录可以将信息自动填写至新订单）</view>
				<u-icon @click="closetip" name="close-circle" color="#4A4A4D "></u-icon>
			</view>
			</view>
			<view class="p-l-30 p-r-30">
				<view class="flex-content" v-for="item in list">
					<retransmission-item :item="item" :select="true"  @selectSend="selectSend" ></retransmission-item>
				</view>
			</view>
			
			
		</mescroll-body>
		
	</view>
</template>

<script>
import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
import {transportList} from '@/api/user'
import {getOrderDetail} from '@/api/order'

export default {
	mixins: [MescrollMixin], // 使用mixin
  data() {
    return {
	  list:[],
      info:{},
	  addressList:[],
	  tip:true
    };
  },
  methods: {
	  closetip(){
		  //关闭提示
		  this.tip=false
	  },
	  selectSend(id){
		  getOrderDetail({
			  id
		  }).then(res=>{
			  this.info = res.data;
			  this.initOrder(id);
		  })
	  },
	  initOrder(id){
		  let arr = this.info.address.concat();
		  this.$store.commit('setTranInfo',arr)
		  arr.forEach((item,index)=>{
		  	if(index==arr.length-1){
		  		let obj1 = {
		  			name:arr[index].start_address,
		  			longitude:arr[index].start_longitude,
		  			latitude:arr[index].start_latitude,
		  		};
		  		let obj2 = {
		  			name:arr[index].end_address,
		  			longitude:arr[index].end_longitude,
		  			latitude:arr[index].end_latitude,
		  		}
		  		this.addressList.push(obj1)
		  		this.addressList.push(obj2)
		  	}
		  	else{
		  		let obj = {
		  			name:arr[index].start_address,
		  			longitude:arr[index].start_longitude,
		  			latitude:arr[index].start_latitude,
		  		};
		  		this.addressList.push(obj)
		  	}
		  })
		  this.$store.commit('setAddress',this.addressList)
		  let car_category_id = this.info.car_category_id;
		  let car_id = this.info.car_id;
		  var label
			if(this.info.label_ids != null){
				   label =  this.info.label_ids.split(',');
			}
			else{
				label =  [];
			}
		  console.log(label)
		  
		  let car_obj = {
			  car_name: this.info.car_name,
			  cover:this.info.cover,
			  id:car_id
		  }
		  let car_info = {
		  	label,
		  	car_category_id,
		  	car_mes:car_obj
		  }
		  console.log(car_info)
		  this.$store.commit('setCarInfo',car_info)
		  
		  uni.redirectTo({
		  	url:'/pages/confirm_order/confirm_order?id=' + id
		  })
	  },
	  
   upCallback(page){
   	const pageNum = page.num; // 页码, 默认从1开始
   	const pageSize = page.size; // 页长, 默认每页10条
   	transportList({
   		page:pageNum,
   		limit:pageSize,
   	}).then(({code,data})=>{
   		if(code==1){
   			if (page.num == 1) this.list = [];
   			// console.log(page.num);
   			const curPageData = data.lists;
   			const curPageLen = curPageData.length;
   			const hasNext = !!data.more;
   			this.list = this.list.concat(curPageData);
   			this.mescroll.endSuccess(curPageLen, hasNext);
   		}
   		
   	}).catch(err=>{
   		this.mescroll.endErr()
   	})
   },
	
  }
};
</script>
<style scoped lang="scss">
	.user-order{
		padding: 10rpx 30rpx;
	}
</style>